import requests
from APIs.baseAPI import BaseAPI
from APIs.loginAPI import Login
from common.config import ip


class Log(BaseAPI):
    def Files(self):
        filedata = {"type": "img", "content": "是"}
        furl = r"D:\2501\apiauto\wx.jpg"
        fileD = {"file": ("wx.jpg",
                          open(furl, "rb"),
                          "image/jpeg")}
        s = requests.post(f"{ip}/file/upload", data=filedata, headers=self.header, files=fileD)
        bid = s.json()
        batchId = bid["batchId"]
        print(batchId)
        return batchId

    def xinLog(self,myjson):
        # myjson = {"categoryId": "1", "content": "是", "tomorrow": "是", "question": "是",
        #           "batchId": "14de2e8c9c1cb0d8cba69e8bb17c3356", "sendUserIds": "", "sendDeptIds": "",
        #           "customerIds": "",
        #           "contactsIds": "", "businessIds": "", "contractIds": ""}
        a = requests.post(f"{ip}/OaLog/addOrUpdate", headers=self.header, json=myjson)
        myJSON = a.json()
        code = myJSON["code"]
        print(code)
        return code

    def selLog(self,myjson):
        # myjson = {"page": "", "limit": 5, "by": "5"}
        L = requests.post(f"{ip}/OaLog/queryList", headers=self.header, json=myjson)
        # 获取logId
        # re = L.json()["data"]["list"][0]["logId"]
        myjson = L.json()
        code = myjson["code"]
        print(code)
        return code

    def updateLog(self,myjson):
        # myjson = {"logId": 6,
        #           "categoryId": "1",
        #           "content": "都是",
        #           "tomorrow": "撒旦",
        #           "question": "阿斯顿",
        #           "batchId": "d0a6a45725deb6a88d4d83208adf64e8",
        #           "sendUserIds": "",
        #           "sendDeptIds": "",
        #           "customerIds": "",
        #           "contactsIds": "",
        #           "businessIds": "",
        #           "contractIds": ""}
        X = requests.post(f"{ip}/OaLog/addOrUpdate", headers=self.header, json=myjson)
        myJSON = X.json()
        code = myJSON["code"]
        return code

    def delLog(self,mydata):
        # mydata = {"logId": 123}
        S = requests.post(f"{ip}/OaLog/deleteById", headers=self.header, data=mydata)
        myJSON = S.json()
        code = myJSON['code']
        print(code)
        return code
    def get_logId(self):
        myjson = {"page": "1", "limit": 5, "by": "5"}
        L = requests.post(f"{ip}/OaLog/queryList", headers=self.header, json=myjson)
        # 获取logId
        logId = L.json()["data"]["list"][0]["logId"]
        print(logId)
        return logId


if __name__ == '__main__':
    lg = Login().get_token()
    ls = Log(token=lg).get_logId()